#!/bin/bash
yum -y install php-fpm php-cli php-mysqlnd php-json php-gd php-mbstring php-xml
sed -i 's/user = apache/user = nginx/g; s/group = apache/group = nginx/g; s/;listen.owner = nobody/listen.owner = nginx/g; s/;listen.group = nobody/listen.group = nginx/g;s/listen.acl_users = apache,nginx/;listen.acl_users = apache,nginx/g;s/;listen.mode = 0660/listen.mode = 0660/g' /etc/php-fpm.d/www.conf

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

sed -i '1i user nginx;' /usr/local/nginx/conf/nginx.conf
sed -i '/^[[:space:]]*server {/,/^[[:space:]]*}/ {
    /^[[:space:]]*server_name[[:space:]]*localhost;/a\
    location ~ \\.php$ {\
        fastcgi_pass unix:/run/php-fpm/www.sock;\
        fastcgi_index index.php;\
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\
        include fastcgi_params;\
    }
}' /usr/local/nginx/conf/nginx.conf

systemctl restart php-fpm
nginx -s reload

echo "<?php phpinfo(); ?>" | sudo tee /usr/local/nginx/html/info.php
